package bitArithmetic;
//TODO:不懂   找出所有子集的异或总和再求和 参考  https://developer.aliyun.com/article/859425
public class basic1863 {
    public int subsetXORSum(int[] nums) {
        int ans = 0;
        // 数字个数
        final int n    = nums.length;
        // 用每一位表示某个数字是否被选中
        final int bits = 1 << n;
        for (int b = 0; b < bits; ++b) {
            int temp = 0;
            for (int i = 0; i < n; ++i) {
                if ((b & (1 << i)) > 0) {
                    temp ^= nums[i];
                }
            }
            ans += temp;
        }
        return ans;
    }

    public static void main(String[] args) {
        basic1863 basic1863 = new basic1863();
        int i = basic1863.subsetXORSum(new int[]{1, 3});
        System.out.println(i);

    }
}
